define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cheliang/index' + location.search,
                    add_url: 'cheliang/add',
                    edit_url: 'cheliang/edit',
                    del_url: 'cheliang/del',
                    multi_url: 'cheliang/multi',
                    import_url: 'cheliang/import',
                    table: 'cheliang',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},

                        {field: 'chepai', title: __('Chepai'), operate: 'LIKE'},
                        {field: 'wangdianid', title: __('Wangdianid')},
                        {field: 'owner', title: __('Owner')},
                        {field: 'chexing', title: __('Chexing'), operate: 'LIKE'},
                        {field: 'chechang', title: __('Chechang')},
                        {field: 'zhujia', title: __('Zhujia'), operate: 'LIKE'},
                        {field: 'zhujiaphone', title: __('Zhujiaphone'), operate: 'LIKE'},
                        {field: 'fujia', title: __('Fujia'), operate: 'LIKE'},
                        {field: 'fujiaphone', title: __('Fujiaphone'), operate: 'LIKE'},
                        {field: 'chejia', title: __('Chejia'), operate: 'LIKE'},
                        {field: 'fadongji', title: __('Fadongji'), operate: 'LIKE'},
                        {field: 'yingyunzheng', title: __('Yingyunzheng'), operate: 'LIKE'},
                        {field: 'zaizhong', title: __('Zaizhong')},
                        {field: 'xingzhi', title: __('Xingzhi'), operate: 'LIKE'},
                        {field: 'nianshenri', title: __('Nianshenri'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'baoxianri', title: __('Baoxianri'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'chengshi', title: __('Chengshi'), operate: 'LIKE'},

                        {field: 'beizhu', title: __('Beizhu'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            $(".btn-add").data("area", ["100%", "100%"]);
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});